#include <algorithm/analytical_model/io/json/converter/analytical_model/CommonPara.h>

#include <cstdint>

using namespace solar;

void solar::tag_invoke(const boost::json::value_from_tag& /*unused*/,
                       boost::json::value& json_value, const CommonPara& common_para)
{
    auto num_gpu_threads = SOLAR_GET_VALUE(CommonPara, num_gpu_threads_, common_para);
    auto path_to_model = SOLAR_GET_VALUE(CommonPara, path_to_model_, common_para);
    json_value = {
        {"num_gpu_threads", num_gpu_threads},
        {  "path_to_model",   path_to_model}
    };
}

auto solar::tag_invoke(const boost::json::value_to_tag<CommonPara>& /*unused*/,
                       const boost::json::value& json_value) -> CommonPara
{
    const auto* value_ptr = json_value.if_object();
    if (value_ptr == nullptr)
    {
        return {};
    }
    CommonPara result;
    if (const auto* num_gpu_threads_value = value_ptr->if_contains("num_gpu_threads"); num_gpu_threads_value != nullptr)
    {
        SOLAR_SET_VALUE(CommonPara, num_gpu_threads_, num_gpu_threads_value->to_number<std::uint32_t>(), result)
    }
    if (const auto* path_to_model_value = value_ptr->if_contains("path_to_model"); path_to_model_value != nullptr)
    {
        SOLAR_SET_VALUE(CommonPara, path_to_model_, path_to_model_value->get_string(), result)
    }
    return result;
}
